﻿package com.chengxusheji.service;

import java.util.ArrayList;
import javax.annotation.Resource; 
import org.springframework.stereotype.Service;
import com.chengxusheji.po.CarState;

import com.chengxusheji.mapper.CarStateMapper;
@Service
public class CarStateService {

	@Resource CarStateMapper carStateMapper;
    /*每页显示记录数目*/
    private int rows = 10;;
    public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}

    /*保存查询后总的页数*/
    private int totalPage;
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    public int getTotalPage() {
        return totalPage;
    }

    /*保存查询到的总记录数*/
    private int recordNumber;
    public void setRecordNumber(int recordNumber) {
        this.recordNumber = recordNumber;
    }
    public int getRecordNumber() {
        return recordNumber;
    }

    /*添加车辆状态记录*/
    public void addCarState(CarState carState) throws Exception {
    	carStateMapper.addCarState(carState);
    }

    /*按照查询条件分页查询车辆状态记录*/
    public ArrayList<CarState> queryCarState(int currentPage) throws Exception { 
     	String where = "where 1=1";
    	int startIndex = (currentPage-1) * this.rows;
    	return carStateMapper.queryCarState(where, startIndex, this.rows);
    }

    /*按照查询条件查询所有记录*/
    public ArrayList<CarState> queryCarState() throws Exception  { 
     	String where = "where 1=1";
    	return carStateMapper.queryCarStateList(where);
    }

    /*查询所有车辆状态记录*/
    public ArrayList<CarState> queryAllCarState()  throws Exception {
        return carStateMapper.queryCarStateList("where 1=1");
    }

    /*当前查询条件下计算总的页数和记录数*/
    public void queryTotalPageAndRecordNumber() throws Exception {
     	String where = "where 1=1";
        recordNumber = carStateMapper.queryCarStateCount(where);
        int mod = recordNumber % this.rows;
        totalPage = recordNumber / this.rows;
        if(mod != 0) totalPage++;
    }

    /*根据主键获取车辆状态记录*/
    public CarState getCarState(int stateId) throws Exception  {
        CarState carState = carStateMapper.getCarState(stateId);
        return carState;
    }

    /*更新车辆状态记录*/
    public void updateCarState(CarState carState) throws Exception {
        carStateMapper.updateCarState(carState);
    }

    /*删除一条车辆状态记录*/
    public void deleteCarState (int stateId) throws Exception {
        carStateMapper.deleteCarState(stateId);
    }

    /*删除多条车辆状态信息*/
    public int deleteCarStates (String stateIds) throws Exception {
    	String _stateIds[] = stateIds.split(",");
    	for(String _stateId: _stateIds) {
    		carStateMapper.deleteCarState(Integer.parseInt(_stateId));
    	}
    	return _stateIds.length;
    }
}
